﻿using DevSupport.Utils;
using Framework.Utility.Mail;
using Microsoft.AspNetCore.Mvc;
using MonitorCode.DBCode;
using MonitorCode.Hangfire;
using MonitorCode.NPS;
using Support.Models.Dto;
using Support.Models.Entities;

namespace DevSupport.Areas.Manage
{
    [ApiController]
    public class OnLineController : ControllerBase
    {
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("/api/Login")]
        public TData Login([FromBody] LoginRequest request)
        { 
            if (request?.UserName == "admin" && request?.Pwd == "admin")
            { 
                HttpContext.Session.SetString(WebConstant.WebSiteSessionName, WebConstant.WebSiteSessionValue);
            } 
            return new TData(ResultTag.success,"登录成功");
        }
        /// <summary>
        /// 获取在线用户
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("api/Manage/GetOnLineList")]
        public async Task<object> GetOnLineList()
        { 
            var data = new { total=WebOnLine.OnLineCount,list=WebOnLine.OnLineList };
            return await Task.FromResult(data);
        }
        /// <summary>
        /// 移除在线用户
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        [Route("api/Manage/DeleteOnLine")]
        public async Task<object> DeleteOnLine(string id)
        {
            var num =  WebOnLine.OnLineList.RemoveAll(c=>c.Id == id); 
            var result = num > 0? true: false;
            return await Task.FromResult(result);
        }
    }
}